//package io.renren.modules.app.message.handler;
//
//import cn.hutool.core.util.ObjectUtil;
//import cn.hutool.core.util.StrUtil;
//import io.renren.modules.app.message.MessageResult;
//import io.renren.modules.app.message.MsgType;
//import io.renren.modules.app.message.constant.JdVopConstant;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.List;
//import java.util.concurrent.LinkedBlockingDeque;
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
///**
// * @author :
// * @version V1.0
// * @Project:
// * @Package
// * @Description: 商品池消息处理器
// * @date
// **/
//@Component(PoolMessageHandler.BeanName)
//@Slf4j
//public class PoolMessageHandler extends AbstractJdVopMessageHandler {
//
//    private static Integer POOLPRODUCTCOUNT=0;
//
//    private static Integer POOLCOUNT=0;
//
////    @Autowired
////    private JdVopProductSoldOutHandler jdVopProductSoldOutHandler;
//
////    @Autowired
////    private IPmsProductService  pmsProductService;
//
////    @Autowired
////    private IPmsProductCategoryService  pmsProductCategoryService;
//
////    @Autowired
////    private JdVopProductCategoryHandler jdVopProductCategoryHandler;
//
//    public static final String BeanName = "MessagePoolHandle";
//
//    private ThreadPoolExecutor productExecutor= new ThreadPoolExecutor(1,5, 20, TimeUnit.MILLISECONDS,new LinkedBlockingDeque<>(200));
//
//    public PoolMessageHandler(ApplicationContext applicationContext) {
//        super(applicationContext);
//        setBeanName(BeanName);
//        productExecutor.allowCoreThreadTimeOut(true);
//    }
//
//
//    @Override
//    public void read(MessageResult msg) {
//        log.info("商品池处理消息总条数：{}======== 时间：{}",POOLCOUNT,new Date());
////        int type = msg.getType();
////        switch (type) {
////            case MsgType.Pool.CHANGE:
////                productExecutor.execute(() -> this.handlePoolChange(msg));
////                break;
////            case MsgType.Pool.STATE:
////                this.handlePoolState(msg);
////                break;
////            default:
////                log.info("JD_VOP NOT FOUND FUN：{}", msg);
////                notifyMsgReadEvent(msg, false);
////        }
//    }
//
//    /**
//     * 商品池发生变化
//     * @param msg
//     */
//    public void handlePoolState(MessageResult msg){
//        ++POOLCOUNT;
//        log.info("商品池添加、删除消息次数============{}=====时间：{}======",POOLPRODUCTCOUNT,new Date());
////        String pageNum=getMsg(msg,MessageResult.pageNum);
////        String poolType=getMsg(msg,MessageResult.poolType);
////        Integer state =Integer.valueOf(getMsg(msg, MessageResult.goodsState));
////        Boolean flag=Boolean.FALSE;
////        if(JdVopConstant.Pool.TYPE_CATE.equals(poolType) && StrUtil.isNotBlank(pageNum)){
////            Long cateId=Long.valueOf(pageNum);
////            PmsProductCategory category=this.pmsProductCategoryService.getById(cateId);
////            boolean hasCategory=   ObjectUtil.isNotNull(category);
////            if(JdVopConstant.Pool.STATE_ADD.equals(state)){
////                if(!hasCategory){
////                    flag=this.jdVopProductCategoryHandler.saveCateGoryByLevel3(cateId);
////                }else{
////                    flag=Boolean.TRUE;
////                }
////            }else if(JdVopConstant.Pool.STATE_DEL.equals(state)){
////                if(hasCategory){
////                    log.warn("product category is del? {}",pageNum);
////                }
////            }else {
////                log.warn("msg.state is error? {}={}",pageNum,state);
////            }
////        }else{
////            log.warn("pool_type nonsupport {}=>{}",poolType,pageNum);
////        }
////        notifyMsgReadEvent(msg,flag);
//    }
//    /**
//     * 处理商品池内商品编号信息
//     * @param msg
//     */
//    public void handlePoolChange(MessageResult msg){
////        ++POOLPRODUCTCOUNT;
//        log.info("商品池内商品添加、删除消息次数============{}=======时间：{}====",POOLPRODUCTCOUNT,new Date());
////        String skuId = getMsg(msg, MessageResult.skuId);
////        Date date=msg.getTime();
////        Integer state =Integer.valueOf(getMsg(msg, MessageResult.goodsState));
////        String pageNum=getMsg(msg,MessageResult.pageNum);
////        PmsProduct pmsProduct=this.pmsProductService.getByOutProductId(skuId);
////        Boolean flag=ObjectUtil.isNotNull(pmsProduct);
////        if(JdVopConstant.Pool.STATE_ADD.equals(state)){
////           if(!flag){
////               //商品不存在则新增商品
////              log.info("pool add product:{}=>{}",pageNum,skuId);
////              flag= this.jdVopProductSoldOutHandler.soldOutSingleProduct(Long.valueOf(skuId),date);
////           }else if(StrUtil.isNotBlank(pageNum) && !StrUtil.equals(pageNum,String.valueOf(pmsProduct.getProductCategoryId()))){
////               //存在且分类不相同,则更新商品的分类ID\分类名称
////               Long cateId=Long.valueOf(pageNum);
////               PmsProductCategory category= this.pmsProductCategoryService.getById(cateId);
////               //检查该分类是否入库，商品分类不存在则不进行消息处理
////               flag=ObjectUtil.isNotNull(category);
////               if(flag){
////                   log.info("product update category:{}=>{}",pageNum,skuId);
////                   flag=this.pmsProductService.updateProductCategory(cateId,category.getName(),pmsProduct.getId());
////               }else{
////                   log.warn("product_category not found {}={}",pageNum,skuId);
////               }
////           }
////        }else if(JdVopConstant.Pool.STATE_DEL.equals(state)){
////            if(flag && !GlobalConstant.DELETE_STATUS.equals(pmsProduct.getDeleteStatus())){
////                //商品存在且未删除 则进行删除操作
////                this.pmsProductService.deleteProductById(pmsProduct.getId());
////            }else{
////                flag=Boolean.TRUE;
////            }
////        }else{
////            log.warn("msg.state is error? {}={}",skuId,state);
////            flag=Boolean.FALSE;
////        }
////        notifyMsgReadEvent(msg,flag);
//    }
//
//
//
//    @Override
//    public void batchRead(List<MessageResult> msgs) {
//        System.out.println("商品池处理");
//        msgs.parallelStream().forEach(this::read);
//    }
//
//}
